import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-10-21
 * Time: 21:09
 */
class Solution {
    public int carFleet(int target, int[] position, int[] speed) {
        int length=position.length;
        Car[] cars=new Car[length];
        for(int i=0;i<length;i++){
            cars[i]=new Car(position[i],speed[i]);
        }
        Arrays.sort(cars,(car1, car2)->car2.position-car1.position);
        int count=1;
        double headTime=(target-cars[0].position)*1.0/cars[0].speed;
        for(int i=1;i<length;i++){
            double time=(target-cars[i].position)*1.0/cars[i].speed;
            //只要跟车头的时间比就行
            //如果又是一个新的车队,及时更换车头的时间
            if(time>headTime){
                count++;
                headTime=time;
            }
        }
        return count;
    }
}

class Car{
    public int position;
    public int speed;
    public Car(int position,int speed){
        this.position=position;
        this.speed=speed;
    }
}